<%@ page contentType="text/html; charset=euc-kr"%>
<%@ page import="java.sql.*"%>
<%@ page import="com.oreilly.servlet.MultipartRequest"%>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ include file="db.jsp" %>

<%
	String realFolder = "C:\\Users\\jspPro\\";
	//String saveFolder = "filestorage";
	

	int sizeLimit = 10 * 1024 * 1024;
	//ServletContext context = getServletContext();
	//realFolder = context.getRealPath(saveFolder);
	String encType = "euc-kr";
	DefaultFileRenamePolicy policy = new DefaultFileRenamePolicy();
	
	MultipartRequest multi = new MultipartRequest(request, realFolder, sizeLimit, encType, policy);

	String fileName = multi.getFilesystemName("userFile");
	String originFileName = multi.getOriginalFileName("userFile");

	File file = multi.getFile("userFile");

	String name = multi.getParameter("name");
	String pass = multi.getParameter("pass");
	String email = multi.getParameter("email");
	String title = multi.getParameter("title");
	String contents = multi.getParameter("contents");

	//Class.forName("com.mysql.jdbc.Driver");
	//String url = "jdbc:mysql://localhost:3306/jsp?useUnicode=true&characterEncoding=euckr";
	//Connection conn = DriverManager.getConnection(url, "root", "hello");

	Statement stmt = conn.createStatement();

	Calendar dateIn = Calendar.getInstance();
	String indate = Integer.toString(dateIn.get(Calendar.YEAR)) + "-";
	indate = indate + Integer.toString(dateIn.get(Calendar.MONTH) + 1) + "-";
	indate = indate + Integer.toString(dateIn.get(Calendar.DATE)) + " ";
	indate = indate + Integer.toString(dateIn.get(Calendar.HOUR_OF_DAY)) + ":";
	indate = indate + Integer.toString(dateIn.get(Calendar.MINUTE)) + ":";
	indate = indate + Integer.toString(dateIn.get(Calendar.SECOND));

	String strSQL = "SELECT Max(num) FROM wtf";
	ResultSet rs = stmt.executeQuery(strSQL);
	int num = 1;

	if (!rs.wasNull()) 
	{
		rs.next();
		num = rs.getInt(1) + 1;
	}
	strSQL = "INSERT INTO wtf (num, name, pass, email, title, contents, writedate, readcount, filename)";
	strSQL = strSQL + "VALUES('" + num + "', '" + name + "', '" + pass + "', '" + email + "',";
	strSQL = strSQL + "'" + title + "', '" + contents + "', '" + indate + "', ' 0 ', '" + fileName + "')";
	stmt.executeUpdate(strSQL);

	stmt.close();
	conn.close();

	response.sendRedirect("listboard.jsp");
%>